package com.example.billbillbangumi;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class Attention extends AppCompatActivity {

    private List<Bangumi> bangumiList = new ArrayList<>();
    private MyDatabaseHelper dbhelper;
    Bangumi bangumi1=new Bangumi("入间同学入魔了",R.drawable.a1);
    Bangumi bangumi2=new Bangumi("厨病激发男孩",R.drawable.a2);
    Bangumi bangumi3=new Bangumi("Dr.STONE石纪元",R.drawable.a3);
    Bangumi bangumi4=new Bangumi("花牌情缘3",R.drawable.a4);
    Bangumi bangumi5=new Bangumi("放学后桌游俱乐部",R.drawable.a5);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attention);
        initBangumis();
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycle_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        BangumiAdapter bangumiAdapter = new BangumiAdapter(bangumiList);
        recyclerView.setAdapter(bangumiAdapter);
    }

    private void initBangumis() {
        dbhelper = new MyDatabaseHelper(this, "Bangumi.db", null, 12);
        SQLiteDatabase db = dbhelper.getWritableDatabase();
        Cursor cursor = db.query("bangumi", null, null, null, null, null, null);
        if (cursor.moveToFirst()) {
            do {
                String bname=cursor.getString(cursor.getColumnIndex("name"));
                String attention = cursor.getString(cursor.getColumnIndex("attention"));
                if(attention.equals("已追番")){
                    if(bangumi1.getName().equals(bname))
                    {
                        bangumiList.add(bangumi1);
                    }
                    else if(bangumi2.getName().equals(bname))
                    {
                        bangumiList.add(bangumi2);
                    }
                    else if(bangumi3.getName().equals(bname))
                    {
                        bangumiList.add(bangumi3);
                    }
                    else if(bangumi4.getName().equals(bname))
                    {
                        bangumiList.add(bangumi4);
                    }
                    else if(bangumi5.getName().equals(bname))
                    {
                        bangumiList.add(bangumi5);
                    }
                }

            } while (cursor.moveToNext());
        }
        cursor.close();
    }
}


